package com.foreveross.chameleon.activity;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.cordova.CordovaActivity;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

/**
 * @description 实现CordovaInterface的Activity类
 * @author zhouzhineng
 *
 */
public class SupportCordovaActivity extends CordovaActivity implements CordovaInterface{

	protected ExecutorService mThreadPool = Executors.newCachedThreadPool();
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}

	@Override
	public void startActivityForResult(CordovaPlugin command, Intent intent,
			int requestCode) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setActivityResultCallback(CordovaPlugin plugin) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Activity getActivity() {
		// TODO Auto-generated method stub
		return this;
	}

	@Override
	public Object onMessage(String id, Object data) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ExecutorService getThreadPool() {
		// TODO Auto-generated method stub
		return mThreadPool;
	}

	@Override
	public void loadUrl(String url) {
		// TODO Auto-generated method stub
		if(url.indexOf("http://bsl-action/") != -1) {
			url = "file:///android_asset/www/" + url.substring("http://bsl-action/".length(),url.length());
		} else if(url.equalsIgnoreCase("http://pop")) {
			appView.backHistory();
			return;
		} else if(url.equalsIgnoreCase("http://home")) {
			url = launchUrl;
		}
		super.loadUrl(url);
	}

	
	
}
